﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DEMO
{
    public enum Fist
    {
        剪刀 = 1,
        石头,
        布
    }
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            int pnum = 0;
            int nnum = 0;
            string b = null;
            login:
            Console.WriteLine("--------------------欢迎进入游戏世界----------------");
            Console.WriteLine("*********************");
            Console.WriteLine("****猜拳，开始*******");
            Console.WriteLine("*********************");
            Console.WriteLine("出拳规则：{0}", Fistlist());

            Console.WriteLine("请选择对方角色：<1：刘备 2：孙权 3：曹操>");
            int a = int.Parse(Console.ReadLine());
            NPCname n = (NPCname)a;
            NPC npc = new NPC();
            npc.Name = n.ToString();
            int nfist = npc.ShowFist();
            Console.WriteLine("请输入你的姓名：");
            Player p = new Player();
            p.Name = Console.ReadLine();
            while (true)
            {

                Console.WriteLine("{0} VS {1} 对战", p.Name, npc.Name);
                Console.WriteLine("开始游戏吗？（y/n）");

                b = Console.ReadLine();
                if (b.Equals("y"))
                {
                    break;
                }
            }
            while (true)
            {
                Console.WriteLine("请出拳：{0},输入对应数字", Fistlist());
                int num = int.Parse(Console.ReadLine());
                Fist f = (Fist)num;
                Console.WriteLine("{0},出拳：{1}", p.Name, f);
                int y = npc.ShowFist();
                Fist j = (Fist)y;
                Console.WriteLine("{0},出拳：{1}", npc.Name, j);
                Judgement jud = new Judgement();
                int gamenum = jud.Judge(num, y);
                Test(gamenum, p.Name);

                if (gamenum == 1)
                {
                    pnum++;
                }
                else if (gamenum == -1)
                {
                    nnum++;
                }
                count++;
                Console.WriteLine("是否开始下一轮？（y/n）");
                b = Console.ReadLine();
                if (b.Equals("n"))
                {
                    break;
                }
            }

            Console.WriteLine("===============================");
            Console.WriteLine("{0} VS {1} 对战", p.Name, npc.Name);
            Console.WriteLine("对战次数：{0}", count);
            Console.WriteLine("姓名        得分");
            Console.WriteLine("{0}          {1}", p.Name, pnum);
            Console.WriteLine("{0}          {1}", npc.Name, nnum);
            if (pnum > nnum)
            {
                Console.WriteLine("结果：{0}赢，{1}笨蛋", p.Name, npc.Name);
            }
            else if (pnum < nnum)
            {
                Console.WriteLine("结果：{0}赢，{1}笨蛋", npc.Name, p.Name);

            }
            Console.WriteLine("是否要进行下一局(y/n)");
            b = Console.ReadLine();
            if (b.Equals("y"))
            {
                pnum = 0;
                nnum = 0;
                count = 0;
                goto login;
            }
            else
            {
                Console.WriteLine("退出程序");
            }

        }

        private static void Test(int gamenum, string name)
        {
            if (gamenum == 0)
            {
                Console.WriteLine("和局，真衰！呵呵，等着瞧吧！");
            }
            else if (gamenum == 1)
            {
                Console.WriteLine("恭喜，{0}赢了", name);
            }
            else
            {
                Console.WriteLine("嘿，笨蛋，你输了！");
            }
           

        }

        private static string Fistlist()
        {
            string Fiststring = "";
            int i = 1;
            foreach (Fist f in Enum.GetValues(typeof(Fist)))
            {
                Fiststring += i + "," + f + "；";
                //Console.WriteLine(f);
                i++;
            }
            return Fiststring;
        }
    }
}
